package com.qk.management.oss;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.comm.Protocol;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.Bucket;
import com.aliyun.oss.model.PutObjectRequest;
import com.qk.management.util.AliyunOSSOperators;

import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.UUID;

/**
 * @author 16778
 * @date 2025/10/8 17:10
 * @description
 */
public class AliYunOssTest {
    public static void main(String[] args) throws Exception {
//        // 创建 ClientBuilderConfiguration 实例，用于配置 OSS 客户端参数
//        ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
//        // 设置签名算法版本为 V4
//        clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
//        // 设置使用 HTTPS 协议访问 OSS，保证传输安全性
//        clientBuilderConfiguration.setProtocol(Protocol.HTTPS);
//
//        // 创建 OSS 客户端实例
//        OSS ossClient = OSSClientBuilder.create()
//                // 以华东1（杭州）地域的外网访问域名为例，Endpoint填写为oss-cn-hangzhou.aliyuncs.com
//                .endpoint("oss-cn-beijing.aliyuncs.com")
//                // 从环境变量中获取访问凭证（需提前配置 OSS_ACCESS_KEY_ID 和 OSS_ACCESS_KEY_SECRET）
//                .credentialsProvider(CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider())
//                // 设置客户端配置
//                .clientConfiguration(clientBuilderConfiguration)
//                // 以华东1（杭州）地域为例，Region填写为cn-hangzhou
//                .region("cn-beijing")
//                .build();
//
//        try {
//            // 列出当前用户的所有 Bucket
////            List<Bucket> buckets = ossClient.listBuckets();
////            // 遍历打印每个 Bucket 的名称
////            for (Bucket bucket : buckets) {
////                System.out.println(bucket.getName());
////            }
//            String dir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM"));
//            String string = UUID.randomUUID().toString();
//            ossClient.putObject(new PutObjectRequest("2025-qk-java-web-ai","111",new File("D://测试.png")));
//        } finally {
//            // 当OSSClient实例不再使用时，调用shutdown方法以释放资源
//            ossClient.shutdown();
//        }
        AliyunOSSOperators oss = new AliyunOSSOperators();
        oss.upload("helloword".getBytes(),"test.txt");
    }
}
